<template>
  <div class="checkTel">
   <van-nav-bar title="标题" class="navbar" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div class="content">
      <van-field v-model="tel" type="tel" label="手机号" placeholder="手机号" />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="primary"
          :disabled="!flag"
          class="custom_btn"
          @click="checkPhone"
        >
          提交
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { showToast } from 'vant';
import { doCheckphone } from "@/apis/user/index";
export default {
  data() {
    return {
      tel: "",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    checkPhone() {
        //用户输入的手机号
      doCheckphone({ tel: this.tel }).then((res) => {
        if (res.data.code == "10005") {
          return showToast("手机号已被注册");
        }
        localStorage.setItem("tel", this.tel);
        this.$router.push("msg");
      });
    },
  },
  computed: {
    flag() {
      return /^1[35789]\d{9}$/.test(this.tel);
    
    },
  },
};
</script>

<style scoped>

.navbar{
    color: rebeccapurple;
}
</style>
